public class Day18 {
    public static void main(String[] args) {
        String a = "1010";
        String b = "1011";
    }

    public String addBinary(String a, String b) {
        int n = a.length()-1;
        int m = b.length()-1;
        int t = 0;//记录进位
        StringBuilder ret = new StringBuilder();
        while(n>=0 || m>=0 || t != 0) {
            if(n>=0) t += a.charAt(n--) - '0';
            if(m>=0) t += b.charAt(m--) - '0';
            ret.append((char)(t%2 + '0'));
            t/=2;
        }
        return ret.reverse().toString();
    }
}
